package servlettest;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

/**
 * Created by hasee on 2017/9/23.
 */
public class ServletOne implements Servlet {
    ServletConfig servletConfig = null;
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        this.servletConfig=servletConfig;
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        PrintWriter out = servletResponse.getWriter();
        Enumeration e = servletConfig.getInitParameterNames();
//       while (e.hasMoreElements()){
//           String name = (String) e.nextElement();
//           String value = servletConfig.getInitParameter(name);
//           out.write(name+"     ");
//           out.write(value+"\n");
//       }

        String value = (String) servletConfig.getServletContext().getAttribute("param");
        out.write("param   =    "+value);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
